package com.jic.data.controller;

import com.jic.common.base.vo.RestResult;
import com.jic.data.model.entity.SaleSingleDetail;
import com.jic.data.model.vo.request.SaleSingleDetailRequest;
import com.jic.data.model.vo.response.*;
import com.jic.data.service.SaleSingleDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 建投数据科技(山东)有限公司
 * @date: 2020-05-09 17:25:19
 */
@RestController
@Slf4j
@RequestMapping("/saleSingleDetail")
@Api(tags = "商品销售-单品-90]")
public class SaleSingleDetailController {
    @Autowired
    private SaleSingleDetailService saleSingleDetailService;

    /**
     * SALE_SINGLE_DETAIL 查询列表（不分页）
     *
     * @param request 前端请求参数
     */
    @PostMapping("/list/sale/product/detail")
    @ApiOperation(value = "商品销售-单品-90-销售单品明细")
    @ResponseBody
    public RestResult<List<SaleSingleDetail>> listSaleSingleDetailAllRecord(@RequestBody SaleSingleDetailRequest request) throws Throwable {
        SaleSingleDetail saleSingleDetail = new SaleSingleDetail();
        BeanUtils.copyProperties(request, saleSingleDetail);
        List<SaleSingleDetail> responseList = saleSingleDetailService.listSingleSaleDetail(saleSingleDetail);

        return RestResult.success(responseList);
    }


    @PostMapping("/list/top/product")
    @ApiOperation(value = "商品销售-单品-90-热销商品top10")
    @ResponseBody
    public RestResult<HistogramChartResponse> listTopProduct(@RequestBody SaleSingleDetailRequest request) throws Throwable {
        SaleSingleDetail saleSingleDetail = new SaleSingleDetail();
        BeanUtils.copyProperties(request, saleSingleDetail);
        HistogramChartResponse list = saleSingleDetailService.selectTopProduct(saleSingleDetail);
        return RestResult.success(list);
    }

}

